import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);

const state = {
    privilege: '',
    user: [],
    u_id: '',
    realname: '',
    email: '',
    registerDate: '',
    lastLogin: '',
    roomtype:'',
};

const getters = {
    getPrivilege(state) {
        return state.privilege;
    },
    getUser(state) {
        return state.user;
    },
    getUID(state) {
        return state.u_id;
    },
    getEmail(state) {
        return state.email;
    },
    getRealname(state) {
        return state.realname;
    },
    getRegisterDate(state) {
        return state.registerDate;
    },
    getLastLogin(state) {
        return state.lastLogin;
    },
    getRoomType(state) {
        return state.roomtype;
    }
};

const mutations = {
    setPrivilege(state, privilege) {
        state.privilege = privilege;
    },
    setUser(state, user) {
        state.user = user;
        //state.privilege = user.privilege.name;
    },
    setEmail(state, email) {
        state.email = email;
    },
    setRealname(state, realname) {
        state.realname = realname;
    },
    setRegisterDate(state, registerDate) {
        state.registerDate = registerDate;
    },
    setLastLogin(state, lastLogin) {
        state.lastLogin = lastLogin;
    },
    setUID(state, u_id) {
        state.u_id = u_id;
    },
    setRoomType(state, roomtype) {
        state.roomtype = roomtype;
    },
    setNull(state) {
        state.privilege = "";
        state.user = "";
        state.u_id = "";
        state.email = "";
        state.realname = "";
        state.registerDate = "";
        state.lastLogin = "";

    }
};

const actions = {
    login(context, privilege, user) {
        context.commit("setPrivilege", privilege);
        context.commit("setUser", user);
    },
    logout(context) {
        context.commit("setNull");
    },
    downFlag(context) {
        context.commit("setFlag", 0);
    },
    upFlag(context) {
        context.commit("setFlag", 1);
    }
};

const store = new Vuex.Store({
    state,
    getters,
    mutations,
    actions
});



export default store;